﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Djs.Tools.Tresor.Gui
{
    public class Tray
    {
        #region NotifyIcon
        public static NotifyIcon GetTrayIcon()
        {
            NotifyIcon ico = new NotifyIcon();

            ico.BalloonTipTitle = "Tresor";
            ico.BalloonTipText = "Trezor je aktivní";
            ico.Icon = Djs.Tools.Tresor.Properties.Resources.view_grid;
            ico.Text = "Trezor je připraven";
            ico.ContextMenuStrip = GetContextMenu();
            ico.Visible = true;

            ico.MouseClick += new MouseEventHandler(ico_MouseClick);
            return ico;
        }
        static void ico_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                MenuOpenTresor();
        }
        #endregion
        #region ContextMenu
        public static ContextMenuStrip GetContextMenu()
        {
            ContextMenuStrip menu = new ContextMenuStrip();
            menu.AutoClose = true;
            menu.AutoSize = true;
            menu.Opacity = 0.95d;
            menu.RenderMode = ToolStripRenderMode.ManagerRenderMode;
            menu.Text = "Tresor";

            ToolStripMenuItem itemOpen = new ToolStripMenuItem() { Text = "Open", Tag = NAME_OPEN };
            itemOpen.Font = new System.Drawing.Font(itemOpen.Font.Name, itemOpen.Font.Size, System.Drawing.FontStyle.Bold);
            itemOpen.Image = Properties.Resources.view_calendar_list_16;
            menu.Items.Add(itemOpen);

            ToolStripMenuItem itemConfig = new ToolStripMenuItem() { Text = "Configure", Tag = NAME_CONFIG };
            itemConfig.Image = Properties.Resources.run_build_configure_16;
            menu.Items.Add(itemConfig);

            ToolStripSeparator itemSep = new ToolStripSeparator();
            menu.Items.Add(itemSep);

            ToolStripMenuItem itemExit = new ToolStripMenuItem() { Text = "Exit", Tag = NAME_EXIT };
            itemExit.Image = Properties.Resources.system_shutdown_16;
            menu.Items.Add(itemExit);

            menu.ItemClicked += new ToolStripItemClickedEventHandler(menu_ItemClicked);
            return menu;
        }
        static void menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            string name = e.ClickedItem.Tag as string;
            switch (name)
            {
                case NAME_OPEN:
                    MenuOpenTresor();
                    break;
                case NAME_CONFIG:
                    MenuOpenConfig();
                    break;
                case NAME_EXIT:
                    MenuCloseApp();
                    break;
            }
        }

        private static void MenuOpenTresor()
        {
            using (Djs.Tools.Tresor.MainForm form = new MainForm())
            {
                form.ShowDialog();
            }
        }

        private static void MenuOpenConfig()
        {
        }

        private static void MenuCloseApp()
        {
            Application.Exit();
        }
        private const string NAME_OPEN = "open";
        private const string NAME_CONFIG = "config";
        private const string NAME_EXIT = "exit";
        #endregion
    }
}
